package cn.zh.system.controller;

import cn.zh.base.util.AjaxResult;
import cn.zh.base.util.PageList;
import cn.zh.system.query.DictionaryQuery;
import cn.zh.system.domain.SystemDictionaryDetail;
import cn.zh.system.service.SystemDictionaryDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/detail")
public class SystemDictionaryDetailController {
    @Autowired
    private SystemDictionaryDetailService service;

    @GetMapping()
    public List<SystemDictionaryDetail> findAll() {
        List<SystemDictionaryDetail> all = service.findAll();
        return all;
    }

    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody SystemDictionaryDetail detail) {
        if (detail.getId() == null) {
            service.add(detail);
        } else {
            service.update(detail);
        }
        return AjaxResult.me().success();
    }

    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Long id) {
        service.delete(id);
        return AjaxResult.me().success();
    }

    @PostMapping
    public PageList<SystemDictionaryDetail> queryByPage(@RequestBody DictionaryQuery query) {
        PageList<SystemDictionaryDetail> list = service.queryByPage(query);
        return list;
    }

    @PatchMapping("/batchdel")
    public AjaxResult batchDel(@RequestBody List<Long> ids) {
        service.batchDel(ids);
        return AjaxResult.me().success();
    }

    @GetMapping("/findDetailByTypeId/{id}")
    public List<SystemDictionaryDetail> findDetailByTypesId(@PathVariable Long id) {
        List<SystemDictionaryDetail> list = service.findDetailByTypesId(id);
        return list;
    }
}
